<template>
    <div>
        <h3>{{sex+'的粉丝'}}</h3>
        <div v-for="item in list">
            <UserItem :item="item" />
        </div>
        <div v-show="list.length===0" style="text-align: center;margin-top: 10%;margin-bottom: 10%;">空空如也</div>
    </div>
</template>

<script>
    import UserItem from "./UserItem";
    export default {
        name: "Third",
        components: {UserItem},
        data(){
            return{
                list:[]
            }
        },
        props:{
            IsMe:false,
            user:{},
        },
        computed:{
            sex(){
                if(this.IsMe){
                    return '我'
                }
                if(this.user.sex===0)
                    return this.user.username
                else if(this.user.sex===1)
                    return '他'
                return '她'
            }
        },
        methods:{
            getData(){
                this.$http.get('/profile/findFollowers/'+this.user.id).then(res=>{
                    if(res.data.status===200) {
                        this.list = res.data.data.followers
                    }
                })
            }
        },
        watch:{
            user:{
                handler(){
                    this.getData()
                },
                deep:true
            }
        },
        mounted() {
            this.getData()
            this.$bus.$on("followAction",()=>{
                this.getData()
            })
        },
        beforeDestroy(){
            this.$bus.$off("followAction")
        }
    }
</script>

<style scoped>

</style>